package com.bestcem.xm.ticket.service.convert;

import com.bestcem.xm.ticket.controller.param.ticket.config.OnlyNotifyConfigParam;
import com.bestcem.xm.ticket.entity.mongo.TicketNotifyConfig;
import org.springframework.util.CollectionUtils;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author liheng
 * @version v1.0
 * @date 2021/9/16 19:57
 */

public class TicketNotifyConfigConvert {
    private TicketNotifyConfigConvert() {
    }

    @Nullable
    public static TicketNotifyConfig paramToEntity(OnlyNotifyConfigParam onlyNotifyConfigParam) {
        if (onlyNotifyConfigParam == null) {
            return null;
        }

        TicketNotifyConfig ticketNotifyConfig = new TicketNotifyConfig();

        ticketNotifyConfig.setId(onlyNotifyConfigParam.getId());
        ticketNotifyConfig.setEvent(onlyNotifyConfigParam.getEvent());
        List<TicketNotifyConfig.ReceiveUser> list = onlyNotifyConfigParam.getReceiver();
        if (!CollectionUtils.isEmpty(list)) {
            ticketNotifyConfig.setReceiverList(new ArrayList<>(list));
            ticketNotifyConfig.setHasReceiver(true);
        } else {
            ticketNotifyConfig.setReceiverList(new ArrayList<>());
            ticketNotifyConfig.setHasReceiver(false);
        }

        List<TicketNotifyConfig.RoleRegion> list1 = onlyNotifyConfigParam.getCcList();
        if (!CollectionUtils.isEmpty(list1)) {
            ticketNotifyConfig.setCcList(list1);
            ticketNotifyConfig.setHasCcList(true);
        } else {
            ticketNotifyConfig.setCcList(new ArrayList<>());
            ticketNotifyConfig.setHasCcList(false);
        }

        // 邮件短信模板添加
        ticketNotifyConfig.setSmsSubject(onlyNotifyConfigParam.getSmsSubject());
        ticketNotifyConfig.setSmsContent(onlyNotifyConfigParam.getSmsContent());
        ticketNotifyConfig.setSmsTemplateId(onlyNotifyConfigParam.getSmsTemplateId());
        ticketNotifyConfig.setEmailContent(onlyNotifyConfigParam.getEmailContent());
        ticketNotifyConfig.setEmailSubject(onlyNotifyConfigParam.getEmailSubject());
        ticketNotifyConfig.setEmailTemplateId(onlyNotifyConfigParam.getEmailTemplateId());

        return ticketNotifyConfig;
    }
}
